import 'package:app_30/res/colors.dart';
import 'package:app_30/res/dimens.dart';
import 'package:app_30/res/gaps.dart';
import 'package:app_30/widgets/click_item.dart';
import 'package:app_30/widgets/load_image.dart';
import 'package:app_30/widgets/my_app_bar.dart';
import 'package:app_30/widgets/my_scroll_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

import '../fencheng_list_page.dart';
import '../ticheng_list_page.dart';
import '../tuijian_list_page.dart';

class MePage extends StatefulWidget {
  const MePage({Key? key}) : super(key: key);

  @override
  State<MePage> createState() => _MePageState();
}

class _MePageState extends State<MePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: const MyAppBar(
          isBack: false,
          centerTitle: '我的',
        ),
        body: MyScrollView(
          children: [
            Column(
              children: <Widget>[
                Container(
                  color: Colours.app_main,
                  alignment: Alignment.center,
                  child: Flex(
                    direction: Axis.vertical,
                    children: const [
                      ClipOval(
                        child: LoadAssetImage(
                          'logo',
                          width: 80,
                          height: 80,
                        ),
                      ),
                      Padding(
                          padding: EdgeInsets.only(bottom: 10.0, top: 10.0),
                          child: Text(
                            'will111',
                            style: TextStyle(
                              color: Colours.material_bg,
                              fontSize: Dimens.font_sp18,
                            ),
                          ))
                    ],
                  ),
                ),
                Gaps.vGap5,
                ClickItem(
                  title: '推荐奖励',
                  onTap: () => goPage(1),
                ),
                ClickItem(
                  title: '提现记录',
                  onTap: () => goPage(2),
                ),
                ClickItem(
                  title: '分成记录',
                  onTap: () => goPage(3),
                ),
                ClickItem(
                  title: '服务中心',
                  onTap: () => launchURL(1),
                ),
                ClickItem(
                  title: '安全中心',
                  onTap: () => launchURL(2),
                ),
                const ClickItem(
                  title: '软件说明',
                ),
                const ClickItem(
                  title: '设置',
                ),
              ],
            ),
          ],
        ));
  }

  goPage(int i) {
    if (i == 1) {
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return TuijianListPage();
        },
      ));
    } else if (i == 2) {
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return TichengListPage();
        },
      ));
    } else if (i == 3) {
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return FenchengListPage();
        },
      ));
    }
  }

  launchURL(int i) {
    if (i == 1) {
      launch('https://www.baidu.cn/');
    } else if (i == 2) {
      launch('https://www.sougou.cn/');
    }
  }
}
